﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eProject.Business;

namespace eProject.Web.UI.Admin
{
    public partial class CompanyManagementEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadData();
            }
        }
        private void loadData() {
            int id = int.Parse( Request.QueryString["Id"].ToString());
            Company com = new Company(id);
            txtAddressCompany.Text = com.Address;
            txtCompanyName.Text = com.Name;
            txtDescription.Text = com.Discription;
            txtEmail.Text = com.Email;
            txtPhoneNumber.Text = com.PhoneNumber;
        }
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(this.Page_Load);
            this.btnSubmit.ServerClick += new EventHandler(btnSubmit_Click);
            this.btnReset.ServerClick += new EventHandler(btnReset_Click);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                int id = int.Parse(Request.QueryString["Id"].ToString());
                Company com = new Company(id);
                com.Name = txtCompanyName.Text.Trim().ToString();
                com.Address = txtAddressCompany.Text.Trim().ToString();
                com.Email = txtEmail.Text.Trim().ToString();
                com.PhoneNumber = txtPhoneNumber.Text.Trim().ToString();
                com.Discription = txtDescription.Text.Trim().ToString();
                com.LastUpdate = DateTime.Now;
                com.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Response.Redirect("CompanyManagementProgram.aspx");
            //Response.Write(id);
        }
        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtAddressCompany.Text = "";
            txtCompanyName.Text = "";
            txtDescription.Text = "";
            txtEmail.Text = "";
            txtPhoneNumber.Text = "";
        }
    }
}